/* 
 * File:   TruthTable.cpp
 * Author: hamed
 * 
 * Created on October 29, 2010, 2:06 PM
 */

#include <math.h>

#include "TruthTable.h"

TruthTable::TruthTable(int varNum) {
    varLength = varNum;
    length = (int)pow(2,varNum);
    table = new TupleK*[length];
    for(int i=0; i< length; i++){
        table[i] = new TupleK(varNum);
        table[i]->setTuple(0);
    }
}

TruthTable::~TruthTable() {
    for(int i=0; i< length; i++){
        delete table[i];
    }
    delete table;
}

TupleK* TruthTable::getTupleAt(int index){
    return table[index];
}

void TruthTable::print(){
    cout<< endl;
    cout<<"-----------------------------------" << endl;
    for(int i=0; i< this->length; i++){
        cout << i << " | " ;//<< //bitset<16>
        for(int k=this->varLength-1; k >= 0; k--){
                cout << (char)this->getTupleAt(i)->GetValueAt(k); //
        }
        cout << endl;
        //cout<<"-----------------------------------" << endl;
    }
}

int TruthTable::getLength(){
    return length;
}

int TruthTable::getWidth(){
    return varLength;
}